package com.qf.smsplatform.deadletter.controller;

import com.qf.smsplatform.deadletter.config.DeadLetterConfig;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DeadController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/dead")
    public String dead(String msg,String expiration){
        rabbitTemplate.convertAndSend(DeadLetterConfig.POJO_EXCHANGE, "aaa.bbb.ccc", msg, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration(expiration);
                return message;
            }
        });
        System.out.println(System.currentTimeMillis());
        return "SUCCESS";
    }

}
